package com.component.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.Date;

import com.component.domain.base.DataBase;
import com.component.enumitem.ModelSumTypeEnum;
import com.component.service.MChannelService;
import com.system.config.SpringContextUtils;
import lombok.Data;

/**
 * 
 * @TableName m_model
 */
@TableName(value ="m_model")
@Data
public class MModel extends DataBase implements Serializable {
    /**
     * 
     */
    @TableId(type = IdType.AUTO)
    private Integer id;

    /**
     * 
     */
    private String modelTitle;

    /**
     * 
     */
    private String modelJson;

    /**
     * 行统计字段
     */
    private String hanSumField;

    /**
     * 列统计字段
     */
    private String lieSumField;

    @TableField(exist = false)
    private String openUrl;

    @TableField("channelId")
    private String channelId;

    @TableField(exist = false)
    private String channelName;

    @TableField("sum_type")
    private String sumtype;

    public String getSumtype() {
        if(this.sumtype==null){
            return ModelSumTypeEnum.DAY_SUM_TYPE_ENUM.getType();
        }
        return sumtype;
    }

    public String getChannelName() {
        if(channelId!=null){
            MChannelService service= SpringContextUtils.getBean(MChannelService.class);
            MChannel mChannel=service.getById(this.channelId);
            if(mChannel != null){
                return mChannel.getChannelname();
            }
        }
        return "";
    }

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;
}